package com.autotest.sync.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author thomas.ning
 * @version 2016年5月5日 下午1:58:40
 */
public class TimeUtil {

	private static final String DAY_DATE = "yyyy-MM-dd";
	private static final String MONTH_DATE = "yyyy-MM";
	private static final String MINUTE_DATE = "yyyy-MM-dd HH:mm";
	private static final String SECOND_DATE = "yyyy-MM-dd HH:mm:ss";
	private static final String FILE_DATE = "yyyy-MM-dd-HH.mm.ss";

	public static String getCurrentDate() {
		return getDateByFormat(new Date(), DAY_DATE);
	}
	
	public static String getFileNameByTime(Long timeStrap){
		if(timeStrap == null){
			return null;
		}
		Date date = new Date(timeStrap);
		return getDateByFormat(date, FILE_DATE);
	}

	public static String getDateByFormat(Date date, String format) {
		if (format == null) {
			format = SECOND_DATE;
		}
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		return sdf.format(date);
	}
	/**
	 * 获取10位长度的时间戳
	 * @return
	 */
	public static String getTimeStamp10(){
		String time = System.currentTimeMillis() + "";
		if(time.length() >10){
			return time.substring(0,10);
		}
		return time;
	}
	/**
	 * 等待时间  单位：ms
	 * @param time
	 */
	public static void sleep(long time){
		try {
			Thread.sleep(time);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
